package com.atguigu.day04;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/4/2
 * 该案例演示了合流算子union
 */
public class Flink05_Union {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        env.setParallelism(1);
        //从8888端口读取数据
        DataStreamSource<String> ds1 = env.socketTextStream("hadoop102", 8888);
        //从8889端口读取数据
        DataStreamSource<String> ds2 = env.socketTextStream("hadoop102", 8889);

        DataStreamSource<Integer> ds3 = env.fromElements(1, 2, 3);
        //ds1.union(ds2).union(ds3.map(i->i + ""));
        //ds1.union(ds2,ds3.map(i->i + ""));
        //通过union将上述两条流进行合并
        DataStream<String> unionDS = ds1
                .union(ds2);
        //打印结果
        unionDS.print();
        //提交作业
        env.execute();

    }
}
